package com.lyz.dataStructure.xiancheng.多线程;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/9/1 18:14
 *@Description:
 **/


/*
现在有T1、T2、T3三个线程，你怎样保证T2在T1执行完后执行，T3在T2执行完后执行？使用join
 */
public class ThreadTest extends Thread {
    private int j =1;
    public ThreadTest(String name){
        setName(name);
    }
    @Override
    public void run(){
        for(int i =1;i<100;i++){
            j++;
        }
        System.out.println("线程"+Thread.currentThread().getName()+"执行完毕"+j);
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadTest threadTest1 = new ThreadTest("T1");
        ThreadTest threadTest2 = new ThreadTest("T2");
        ThreadTest threadTest3 = new ThreadTest("T3");
        //线程1
        threadTest1.start();
        threadTest1.join();
        //线程2
        threadTest2.start();
        threadTest2.join();
        //线程3
        threadTest3.start();
        threadTest3.join();
    }

}
